<!DOCTYPE html>
<html>
    <head> 
        <meta name="viewport" content="initial-scale=1, maximum-scale=3, minimum-scale=1, user-scalable=no">
        <meta charset="utf-8"> 
        <title>健康打卡</title>
        <link rel="stylesheet" type="text/css" href="../static/question/css/question.css">
        {# javascript脚本#}
        <script src = "../static/laydate/laydate.js"></script>
        <script src="https://cdn.staticfile.org/jquery/2.0.3/jquery.min.js"></script>
        <script src="../static/question/js/helper.js"></script>


    </head>


    <body>
        <div>
            <h1>每日员工健康打卡</h1>
            <p class="person"><img src="../static/question/images/person.jpg" alt="person" width="16" height="16">实名问卷</p>

            <p>所有员工须每日健康打卡，未满隔离期（14）天的返回本省员工还须登入隔离人员补充打卡，打卡有效时间均为早上6点到晚上10点。按时、完整和据实填报将奖励2元/人·日，若逾期、不完整或不据实填报将追究个人责任。</p>
            <br>
            <b>姓名:</b>
            <input type="text" class="input1" id="name"  value="" disabled>
            <b> 工号:</b>
            <input type="text" class="input1" id="num" value="" disabled>
            <b> 部门: </b>
            <input type = "text" class="input1" id = "dept"  value="" disabled>
            <b> 党支部:</b>
            <input type="text" class="input1" id="party"  value="" disabled>

            <b> 打卡日期:</b>
            <input type="text" placeholder="请选择打卡日期" id="test1" >

            <script>
            function initradio(rName,rValue){
                var rObj = document.getElementsByName(rName);

                for(var i = 0;i < rObj.length;i++){
                    if(rObj[i].value == rValue){
                        rObj[i].checked =  'checked';
                    }
                }
            }

            window.onload =function () {
                special_case_input.onfocus = function () {
                    if(special_case_input.value.trim()=="如无，不填写任何内容")
                        special_case_input.value = "";
                }
                special_case_input.onblur = function () {
                    if(special_case_input.value.trim()=="")
                        special_case_input.value = "如无，不填写任何内容";
                }
            }

            function check() {
            var date = new Date();time = date.getHours();
            if(time<6||time>22) {
                alert("请在规定时间内(6:00-22:00)提交");
                return false;
            }
            else{
                var sObj = document.getElementById("submit");
                if(sObj.value=="提交"){
                    alert("提交成功！");
                    sObj.value="修改";
                }
                else
                    alert("修改成功！");
                return true;
                }
            }
            {#获得当前时间#}
            function getNowFormatDate() {
          var date = new Date();
          var seperator1 = "-";
          var seperator2 = ":";
          var month = date.getMonth() + 1;
          var strDate = date.getDate();
          if (month >= 1 && month <= 9) {
              month = "0" + month;
          }
          if (strDate >= 0 && strDate <= 9) {
              strDate = "0" + strDate;
          }
          var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
              + " " + date.getHours() + seperator2 + date.getMinutes()
              + seperator2 + date.getSeconds();
          return currentdate;
      }
        var days={};
            days['2020-7-26']='正常';
            days['2020-7-25']='正常';
            {#日历控件#}
            laydate.render({
                elem: '#test1',
                value: new Date(),
                max: getNowFormatDate(), // 设置日期时间的最大值
                mark: days,
                showBottom: false,
                calendar: true,
                done: function (value, date) {
                    $.ajax({
                        url: 'ajax_fresh',
                        type: 'GET',
                        data: {
                            'date': value,
                        },
                        'success': function (data) {
                            //回调函数，当请求成功自动触发此方法
                            //data自动接收后台传过来的内容
                            //判断是否已经注册
                            if (data['ret']) {
                                var today = new Date();
                                var year = today.getFullYear(),month = today.getMonth()+1,day = today.getDate();
                                if(month<10){
                                    month = month.toString();
                                    month = '0'+month;
                                }
                                today = year+'-'+month+'-'+day;
                                alert(today)
                                if(value!=today) {
                                    var sObj = document.getElementById("submit");
                                    sObj.setAttribute("disabled", true);
                                    sObj.style.backgroundColor = '#555555';//设置背景色
                                }
                                else{
                                    var sObj = document.getElementById("submit");
                                    sObj.removeAttribute("disabled");
                                    sObj.style.backgroundColor = '#6495ED';//设置背景色
                                }
                                {#展示信息#}
                                initradio("1", data["1"]);
                                initradio("2", data["2"]);
                                initradio("3", data["3"]);
                                initradio("4", data["4"]);
                                initradio("5", data["5"]);

                            } else {
                                alert("所选日期没有打卡信息！")
                            }

                        }
                    })
                }
            })
            //墨绿主

        </script>

        </div>

        <div>
        {# 加上指定时间提交 #}
            <form name="myform" action="answer" method="POST" onsubmit="return check()" >
                {% csrf_token %}

                <b class="red">*</b>
                <b>1.本人的身体健康情况？</b><br>
                <br>
                <input type="radio" name="1" value="1" required checked="checked"/>身体健康，无异常<br>
                <br>
                <input type="radio" name="1" value="2" required />有出现发热、乏力、呼吸困难等与新冠肺炎相关症状<br>
                <br>
                <input type="radio" name="1" value="3" required />有其他疾病症状<br>
                <br>

                <b class="red">*</b>
                <b>2.与本人共同居住的家人是否有出现发热、乏力、呼吸困难等与新冠肺炎相关症状？</b><br>
                <br>
                <input type="radio" name="2" value="1" required checked="checked"/>无<br>
                <br>
                <input type="radio" name="2" value="2" required/>有<br>
                <br>

                <b class="red">*</b>
                <b>3.本人落实疫情防控及复工复产措施情况？</b><br>
                <br>
                <input type="radio" name="3" value="1" required checked="checked"/>正常上班<br>
                <br>
                <input type="radio" name="3" value="2" required/>正常轮休，没有上班<br>
                <br>
                <input type="radio" name="3" value="3" required/>其他原因，没有上班<br>
                <br>
                <input type="radio" name="3" value="4" required/>本人及共同居住的家人有从境外、北京等高风险地区回来的，或已按有关部门要求仍在隔离中<br>
                <br>

                <b class="red">*</b>
                <b>4.本人工作场所的环境健康情况？</b><br><br>
                <input type="radio" name="4" value="1" required checked="checked"/>干净整洁、通风良好、环境舒适<br>
                <br>
                <input type="radio" name="4" value="2" required />还需要进一步整治或改善<br>
                <br>

                <b class="red">*</b>
                <b>5.本人工作期间的心理健康情况？</b><br><br>
                <input type="radio" name="5" value="1" required checked="checked"/>沟通渠道畅通，工作心情愉快<br>
                <br>
                <input type="radio" name="5" value="2" required/>找不到人倾诉，需要关心帮助<br>
                <br>

                <b>6.本人有无需要向公司特别报告及说明事项？</b><br><br>
                <input type="text" name="6" id = "special_case_input",style="width:100%" class="inp" value="如无，不填写任何内容">

                <br>
                <br>
                <br>
                <input type="submit" class="submit" id = "submit" value="提交" >

            </form>
        </div>
    </body>
    {#  实现radio按钮初始化 #}
    <script>

        var tmp = {{ info|safe }}
           {#加载用户信息#}
        var nameObj = document.getElementById("name");
        var numObj = document.getElementById("num");
        var deptObj = document.getElementById("dept");
        var partyObj = document.getElementById("party");

        nameObj.value  = tmp["name"];
        numObj.value = tmp["num"];
        deptObj.value = tmp["dept"];
        partyObj.value = tmp["party"];
         {#根据情况修改submit的value值#}
        var isfirst = tmp["isfirst"];
        var sObj = document.getElementById("submit");
        if(!isfirst)
            sObj.value = "修改";
        {#记住上次的值#}
        if(Object.keys(tmp).length>5) {


            initradio("1", tmp["1"]);
            initradio("2", tmp["2"]);
            initradio("3", tmp["3"]);
            initradio("4", tmp["4"]);
            initradio("5", tmp["5"]);

        }

    </script>
</html>
